<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置<small>用户管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>用户管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="姓名/电话号码/身份" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="enterQuery()"></el-input>
                <el-button @click="conditionQuery()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table
                    :data="dataList"
                    border
                    style="width: 100%">
                <el-table-column
                        fixed
                        align="center"
                        prop="username"
                        label="用户名"
                        width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="gender"
                        label="性别"
                        width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="birthday"
                        label="生日"
                        width="150">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="password"
                        label="密码"
                        width="300">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="remark"
                        label="说明"
                        width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="station"
                        label="状态"
                        width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="telephone"
                        label="手机号码"
                        width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="roles[0].name"
                        label="角色名称"
                        width="120">
                </el-table-column>
                <el-table-column
                        align="center"
                        fixed="right"
                        label="操作"
                        width="150">
                    <template slot-scope="scope">
                        <el-button @click="handleUpdate(scope.row)" type="primary" size="mini">编辑</el-button>
                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
           <!-- <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="username" label="用户名" align="center"></el-table-column>
                <el-table-column prop="password" label="密码" align="center"></el-table-column>
                <el-table-column prop="gender" label="性别" align="center"></el-table-column>
                <el-table-column prop="birthday" label="生日" align="center"></el-table-column>
                <el-table-column prop="telephone" label="电话号码" align="center"></el-table-column>
                <el-table-column prop="station" label="身份" align="center"></el-table-column>
                <el-table-column prop="remark" label="备注" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>-->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- TODO: 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增用户" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form status-icon :model="formData" ref="dataAddForm"
                                         label-position="right"
                                         label-width="100px"
                                         :rules="rules">
                                    <el-row>
                                        <el-col :span="12" style="margin-left: -20px">
                                            <el-form-item label="用户名" prop="username">
                                                <el-input v-model="formData.username"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12" style="margin-right: 20px">
                                            <el-form-item label="密码" prop="password">
                                                <el-input placeholder="请输入密码" v-model="formData.password"
                                                        type="password"  show-password></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12" style="margin-left: -20px">
                                            <el-form-item label="性别" prop="gender">
                                                <el-select v-model="formData.gender">
                                                    <el-option label="未知" value="未知"></el-option>
                                                    <el-option label="男" value="男"></el-option>
                                                    <el-option label="女" value="女"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12" style="margin-right: 20px">
                                            <el-form-item label="电话号码" prop="telephone">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12" style="margin-left: -20px">
                                            <div class="block" style="text-align: right">
                                                <span class="demonstration">生日</span>
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </div>
                                        </el-col>

                                        <el-col :span="12" style="margin-right: 20px">
                                            <el-form-item label="身份">
                                                <el-input v-model="formData.station"></el-input>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="24" style="margin-left: -20px">
                                            <el-form-item label="备注">
                                                <el-input v-model="formData.remark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="角色信息" name="second">
                                <!--                                TODO: 新增 role table-->
                                <el-table
                                        ref="addFilterTable"
                                        :data="tableData"
                                        style="width: 100%;height: 30px"
                                        height="240"
                                        border
                                        :row-class-name="roleTableRowClassName"
                                        @selection-change="handleSelectionChange"
                                >
                                    <el-table-column
                                            type="selection"
                                            width="50">
                                    </el-table-column>
                                    <el-table-column
                                            prop="name"
                                            label="角色名"
                                            width="110"
                                            height="40"
                                            sortable
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="keyword"
                                            label="关键字"
                                            width="180"
                                            height="40"
                                            sortable
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="description"
                                            label="描述"
                                            fit
                                            height="40"
                                    >
                                    </el-table-column>
                                </el-table>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- TODO: 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑用户" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form status-icon :model="formData" ref="dataEditForm" :rules="rules"
                                         label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12" style="margin-left: -20px">
                                            <el-form-item label="用户名" prop="name">
                                                <el-input v-model="formData.username"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12" style="margin-right: 20px">
                                            <el-form-item label="密码" prop="password">
                                                <el-input placeholder="请输入密码" v-model="formData.password"
                                                          type="password"  show-password="true"></el-input>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="12" style="margin-left: -20px">
                                            <el-form-item label="性别" prop="gender">
                                                <el-select v-model="formData.gender">
                                                    <el-option label="未知" value="未知"></el-option>
                                                    <el-option label="男" value="男"></el-option>
                                                    <el-option label="女" value="女"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12" style="margin-right: 20px">
                                            <el-form-item label="电话号码" prop="telephone">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12" style="margin-left: -20px">
                                            <div class="block" style="text-align: right">
                                                <span class="demonstration">生日</span>
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="日期时间">
                                                </el-date-picker>
                                            </div>
                                        </el-col>
                                        <el-col :span="12" style="margin-right: 20px">
                                            <el-form-item label="身份">
                                                <el-input v-model="formData.station"></el-input>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="24" style="margin-left: -20px">
                                            <el-form-item label="备注">
                                                <el-input v-model="formData.remark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="角色信息" name="second">

                                <!--                                TODO: 编辑 role table-->
                                <el-table
                                        ref="editFilterTable"
                                        :data="roleData"
                                        style="width: 100%;height: 30px"
                                        height="240"
                                        border
                                        :row-class-name="roleTableRowClassName">
                                    <el-table-column
                                            prop="name"
                                            label="角色名"
                                            width="110"
                                            height="40"
                                            sortable
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="keyword"
                                            label="关键字"
                                            width="180"
                                            height="40"
                                            sortable
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="description"
                                            label="描述"
                                            fit
                                            height="40"
                                    >
                                    </el-table-column>
                                </el-table>
                                <div style="text-align: right">
                                    <el-button type="primary" icon="el-icon-edit" circle
                                               @click="handleRoleListDialogVisibleEdit()"></el-button>
                                </div>

                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>

                <!--                TODO: role列表编辑弹窗 穿梭框-->
                <el-dialog title="编辑角色" :visible.sync="roleListDialogVisibleEdit">
                    <div style="text-align: center">
                        <el-transfer
                                :left-default-checked="transfer.emptyArr"
                                :right-default-checked="transfer.emptyArr"
                                filterable
                                :filter-method="filterMethod"
                                filter-placeholder="请输入用户名称"
                                style="text-align: left;display: inline-block"
                                :data="transfer.roleSelectableData"
                                v-model="transfer.roleSelectedData"
                                :titles="['可选', '已选']"
                                @change="handleChange"
                                :props="{key: 'id',label: 'name'}"
                                ref="roleTransfer"
                        >
                            <div style="text-align: right" slot="right-footer">
                                <el-button @click="submitChangeRoleForUser"
                                           icon="el-icon-check" circle
                                           type="warning">
                                </el-button>
                            </div>

                        </el-transfer>
                    </div>

                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    //TODO: 自定义校验
    let checkTelephone = (rule, value, callback) => {
        setTimeout(() => {

            let regex = /^1[3456789]\d{9}$/;
            if (!regex.test(value)) {
                callback(new Error('请输入正确的电话号码!!'));
            } else {
                callback();
            }
        }, 500);
    };

    //TODO: vue
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增表单中对应的角色列表数据
            roleData: [],//编辑表单中对应的角色列表数据

            currentRowInfo: {}, //当前行信息

            //TODO: 编辑 穿梭框数据容器
            transfer: {
                emptyArr: [], //空数组
                roleSelectableData: [],//对应的角色可选列表数据
                roleSelectedData: [],//对应的角色已选列表数据
                initRoleForUserIds: [], //对应角色初始id列表
                ChangeRoleForUserIdsForDelete: [], //对应的角色需要删除的id 列表
            },
            // TODO-----------------------------------------

            roleIds: [],//新增和编辑表单中角色对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            roleListDialogVisibleEdit: false,//控制role列表编辑窗口显示/隐藏

            //TODO: 校验规则
            rules: {//校验规则
                telephone: [
                    {required: true, message: '电话号码为必填项', trigger: 'blur'},
                    {validator: checkTelephone, trigger: 'blur'}
                ],
                username: [
                    {required: true, message: '姓名为必填项', trigger: 'blur'},
                    {min: 2, max: 10, message: '长度在 2 到 10个字符', trigger: 'blur'}
                ],
                password: [
                    {required: true, message: '密码为必填项', trigger: 'blur'},
                    {min: 4, max: 200, message: '长度必出大于 4个字符', trigger: 'blur'}
                ],
                gender: [
                    {required: true, message: '性别为必填项', trigger: 'blur'},
                ]
            }
        },
        //vue 被创建就分页查询
        created() {
            this.findPage();
        },

        //TODO: 监听dialog的开闭状态并执行异步校验
        watch: {
            dialogFormVisible(val) {
                !val && setTimeout(() => {
                    this.$refs['dataAddForm'].clearValidate();
                    this.$refs.addFilterTable.clearSort();
                }, 0);
            },
            dialogFormVisible4Edit(val) {
                !val && setTimeout(() => {
                    this.$refs['dataEditForm'].clearValidate();
                    this.$refs.editFilterTable.clearSort();
                }, 0);
            },
            roleListDialogVisibleEdit(val) {
                val && setTimeout(() => {
                    //查询所有角色数据
                    this.queryAllRole();

                }, 0);
                !val && setTimeout(() => {
                    //    清除穿梭框搜索内容,清除所有clearQuery 需要v2.2+
                    //左边
                    this.$refs.roleTransfer.$children["0"]._data.query = '';
                    // 清空右边搜索
                    this.$refs.roleTransfer.$children["3"]._data.query = '';

                    //    清空穿梭框选择状态   失败!
                    this.transfer.emptyArr.length = 0;
                }, 0);
            }
        },

        methods: {
            //TODO: 权限不足提示
            showMessage(r){
                if(r == 'Error: Request failed with status code 403'){
                    //权限不足
                    this.$message.error('无访问权限');
                }else{
                    this.$message.error('未知错误');
                }
            },
            enterQuery() {
                this.findPage();
            },

            //TODO:  重置表单
            resetForm() {
                //    等于空完事
                this.formData = {};

                //    每次弹窗显示第一个tabs
                this.activeName = "first";
                //    每次弹窗取消勾选角色,清空id数组
                this.roleIds = [];
            },

            // TODO: 弹出添加窗口
            handleCreate() {
                //        每次弹出清空表单数据
                this.resetForm();
                //    dialog visible.sync true完事
                this.dialogFormVisible = true;

                // //清除校验规则
                // this.$refs['dataAddForm'].clearValidate();

                //    弹出即查询所有role
                this.queryAllRole();

            },

            //TODO: 查询所有Role
            queryAllRole() {
                axios.post("/role/queryAllRole.do").then((res) => {
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            },

            //TODO: role列表row样式
            roleTableRowClassName({row, rowIndex}) {
                if (rowIndex % 2 == 1) {
                    return 'warning-row';
                } else if (rowIndex % 2 == 0) {
                    return 'success-row';
                }
                return '';
            },

            //TODO: 添加
            handleAdd() {

                //表单校验是否合法在添加
                //语法this.$refs["表单ref"].validate((valid) =>{})
                this.$refs["dataAddForm"].validate((valid) => {
                    //    给予合法提示
                    if (valid) {
                        //判断是否添加了角色
                        if (this.roleIds.length == 0) {
                            this.$message.error("请至少添加一个角色");
                            return;
                        }
                        //  发送axios请求  将表单对象与roleIds数组作为参数传递
                        let param = {
                            formData: this.formData,
                            roleIds: this.roleIds
                        };
                        axios.post("/user/addUser.do", param).then((res) => {
                            //    判断数据是否添加成功并给予消息提示
                            if (res.data.flag) {

                                this.$message.success(res.data.message);
                                //    添加成功关闭弹出框
                                this.dialogFormVisible = false;
                                //    成功后查询
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);
                            }

                        }).catch((r)=>{
                            this.showMessage(r)
                        })

                    } else {
                        this.$message.error("表单数据不合法噢~~,重新输入吧")
                    }
                });

            },

            //TODO: 分页查询
            findPage() {
                //json数据参数,name与bean属性要一致
                let param = {
                    //当前页
                    currentPage: this.pagination.currentPage,
                    //页码
                    pageSize: this.pagination.pageSize,
                    //    查询条件
                    queryString: this.pagination.queryString
                };

                //    发送axios请求查询分页数据与总信息数
                axios.post("/user/queryPage.do", param).then((res) => {
                    //    判断flag
                    if (res.data.flag) {
                        //    为页面数据数组赋值
                        this.dataList = res.data.data.rows;
                        //    为页面信息总数赋值
                        this.pagination.total = res.data.data.total;
                    } else {
                        //错误提示信息
                        this.$message.error(res.data.message);
                    }
                }).catch((r)=>{
                    this.showMessage(r)
                })

            },

            //TODO: 关键字查询
            conditionQuery() {
                this.pagination.currentPage = 1;
                this.findPage();
            },

            //TODO: 切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //TODO: 为新增user时role id 数组赋值
            handleSelectionChange(val) {
                // console.log(val);
                this.roleIds.length = 0;
                for (let i = 0; i < val.length; i++) {
                    this.roleIds.push(val[i].id)
                }
                // console.log(this.roleIds);
            },

            //TODO:  弹出编辑窗口
            handleUpdate(row) {

                //不知道为什么首次打开要查询两次
                //查询所有角色数据
                this.queryAllRole();

                //    每次弹窗显示第一个tabs
                this.activeName = "first";
                //visible.sync = true
                this.dialogFormVisible4Edit = true;

                // //清除校验规则
                // this.$refs['dataEditForm'].clearValidate();

                //    数据回显 row就是封装了当前行的所有数据,直接赋值表单对象
                this.formData = JSON.parse(JSON.stringify(row));

                //   查询对应角色
                this.queryRoleForUser(row);


            },

            //    TODO: 查询对应角色
            queryRoleForUser(row) {

                //将row提取
                this.currentRowInfo = row;

                let param = {id: row.id};
                axios.post("/role/queryRoleForUser.do", param).then((res) => {
                    //判断并给出相应提示消息
                    if (res.data.flag) {
                        //填充数据
                        this.roleData = res.data.data;
                        //this.$message.success(res.data.message);
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            },

            // TODO: 弹出对应role列表编辑穿梭框
            handleRoleListDialogVisibleEdit() {

                //弹出
                this.roleListDialogVisibleEdit = true;

                // console.log(this.transfer.emptyArr);

                //遍历取出id与name重新赋值给数组
                let arrCollection = this.forEachData(this.tableData, this.roleData);
                //可选穿梭框列表赋值
                this.transfer.roleSelectableData = arrCollection.arrALL;

                //已选穿梭框列表赋值
                this.transfer.roleSelectedData = arrCollection.arrSelected;

                //将已选穿梭框数组记录初始值
                this.transfer.initRoleForUserIds = [].concat(arrCollection.arrSelected);

            },

            //TODO: 穿梭框搜索过滤方法...
            filterMethod(query, role) {
                // console.log(query)
                // console.log(role)
                return role.name.indexOf(query) > -1;
            },

            //TODO: 穿梭框change方法
            handleChange(value, direction, movedKeys) {
                //可以通过direction回调right/left 来进行操作，right：把数据移到右边，left把数据移到左边
                if (direction === "right") {
                }
                if (direction === "left") {
                }

            },

            // TODO: 遍历取出id与name重新赋值给数组
            forEachData(allSelectData, selectedData) {
                //重新生成对象数组
                let arrALL = new Array();
                let arrSelected = new Array();
                for (let i = 0; i < allSelectData.length; i++) {
                    arrALL.push({
                        id: allSelectData[i].id,
                        name: (i + 1) + ".\t--\t" + allSelectData[i].name,
                    })
                }

                for (let i = 0; i < selectedData.length; i++) {
                    arrSelected.push(selectedData[i].id);
                }


                //返回对象
                return {
                    arrALL: arrALL,
                    arrSelected: arrSelected
                };

            },

            //TODO: 修改user对应role列表按钮
            submitChangeRoleForUser() {

                if (this.transfer.roleSelectedData.length == 0) {
                    this.$message.error("请至少添加一个角色");
                    return;
                }

                // 重置id数组
                this.transfer.ChangeRoleForUserIdsForDelete.length = 0;


                // console.log(this.transfer.initRoleForUserIds);

                //    处理最终发送后台的roleId数据
                let param = this.finalRoleIdsHandle();

                // console.log(param);
                //发送请求更新对应角色数据
                axios.post("/user/updateRoleForUserByDetail.do", param).then((res) => {
                    if (res.data.flag) {
                        this.$notify({
                            title: '提示',
                            message: res.data.message,
                            duration: 2000,
                            type: 'success'
                        });
                        //再次查询对应角色
                        this.queryRoleForUser(this.currentRowInfo);
                        //成功后关闭窗口
                        this.roleListDialogVisibleEdit = false;
                    } else {
                        this.$notify.error({
                            title: '提示',
                            message: res.data.message,
                            duration: 3000,
                        });
                    }
                });

            },

            //TODO: 包装数据,返回最终需要删除与添加的id数组,当前user id
            finalRoleIdsHandle() {
                //去重
                //外循环初始数组
                for (let i = 0; i < this.transfer.initRoleForUserIds.length; i++) {
                    let flag = false;
                    //内循环已选数组
                    for (let j = 0; j < this.transfer.roleSelectedData.length; j++) {
                        //如果出现相同元素,删除并改变标记
                        if (this.transfer.initRoleForUserIds[i] == this.transfer.roleSelectedData[j]) {
                            flag = true;
                            //删除
                            this.transfer.roleSelectedData.splice(j, 1);
                            j--;
                        }
                    }
                    //如果外循环一次没有相同元素,添加需要删除的role id
                    if (!flag) {
                        this.transfer.ChangeRoleForUserIdsForDelete.push(this.transfer.initRoleForUserIds[i])
                    }

                }

                //返回包装后数据
                return {
                    deleteIds: this.transfer.ChangeRoleForUserIdsForDelete,
                    // 重定义数组记录需要添加的id
                    addIds: [].concat(this.transfer.roleSelectedData),
                    currentRowId: this.currentRowInfo.id
                };
            },

            //TODO: 编辑
            handleEdit() {
                //    表单校验
                this.$refs["dataEditForm"].validate((valid) => {
                    if (valid) {
                        //判断是否存在对应角色
                        if (this.roleData.length == 0) {
                            this.$message.error("请至少添加一个角色");
                            return;
                        }
                        //    发送请求,根据id修改数据,数据回显时id已存在formData中了
                        axios.post("/user/updateUser.do", this.formData).then((res) => {
                            //    判断是否修改成功
                            if (res.data.flag) {
                                this.$message.success(res.data.message);
                                //    成功后关闭窗口
                                this.dialogFormVisible4Edit = false;
                                //    成功后查询
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }).catch((r)=>{
                            this.showMessage(r)
                        });
                    } else {
                        this.$message.error("改的啥玩意??,重改!")
                    }
                });
            },

            //TODO:  删除
            handleDelete(row) {
                //提示框
                this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //判断当前页数据是否为最后一条并修改当前页码
                    if (this.dataList.length == 1 && this.pagination.currentPage > 1) {
                        this.pagination.currentPage = this.pagination.currentPage - 1;
                    }
                    //    传入id完事
                    let param = {id: row.id};
                    axios.post("/user/deleteUser.do", param).then((res) => {
                        //    判断是否删除成功
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                            //    删完查询
                            this.findPage();
                        } else {
                            this.$message.error(res.data.message);
                        }
                    }).catch((r)=>{
                        this.showMessage(r)
                    });
                }).catch(() => {
                    this.$message('已取消删除');
                });

            }
        }

    })
</script>
</html>
